//
//  ViewController.m
//  Gas
//
//  Created by 张伟良 on 17/5/22.
//  Copyright © 2017年 HongHu. All rights reserved.
//

#import "ViewController.h"
#import <CommonCrypto/CommonCryptor.h>
//#import "GTMBase64.h"

@interface ViewController ()



@end

@implementation ViewController



- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    self.view.backgroundColor = [UIColor colorWithHexString:@"#F2F4F8"];

    self.edgesForExtendedLayout = UIRectEdgeNone;
    
    if (self.navigationController.childViewControllers.count > 1) {
        
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        //        [button setTitle:@"返回" forState:UIControlStateNormal];
        [button setImage:[UIImage imageNamed:@"back2"] forState:UIControlStateNormal];
        //        [button setImage:[UIImage imageNamed:@"navigationReturnClick"] forState:UIControlStateHighlighted];
        CGRect frame = button.frame;
        frame.size = CGSizeMake(30, 30);
        button.frame = frame;
        //        button.backgroundColor = [UIColor greenColor]
        button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        //        button.contentEdgeInsets = UIEdgeInsetsMake(0, -10, 0, 0);
        //        [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        //        [button setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];
        self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
        [button addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
        self.backButton = button;
    }
    

//    // 校验域
//    NSMutableData *data1 = [self convertHexStrToData:@"2312"];
//
//    Byte onTimeChargeOrder[1] = {0};
//    onTimeChargeOrder[0] = [self calCheckSum2:data1];
//    NSData *data = [NSData dataWithBytes:onTimeChargeOrder length:sizeof(onTimeChargeOrder)];
//
//    NSLog(@"构造完的数据是 %@",data1);
}

//// 16进制字符串转换成NSData
//- (NSMutableData *)convertHexStrToData:(NSString *)str {
//    if (!str || [str length] == 0) {
//        return nil;
//    }
//
//    NSMutableData *hexData = [[NSMutableData alloc] initWithCapacity:8];
//    NSRange range;
//    if ([str length] % 2 == 0) {
//        range = NSMakeRange(0, 2);
//    } else {
//        range = NSMakeRange(0, 1);
//    }
//    for (NSInteger i = range.location; i < [str length]; i += 2) {
//        unsigned int anInt;
//        NSString *hexCharStr = [str substringWithRange:range];
//        NSScanner *scanner = [[NSScanner alloc] initWithString:hexCharStr];
//
//        [scanner scanHexInt:&anInt];
//        NSData *entity = [[NSData alloc] initWithBytes:&anInt length:1];
//        [hexData appendData:entity];
//
//        range.location += range.length;
//        range.length = 2;
//    }
//
//    NSLog(@"hexdata: %@", hexData);
//    return hexData;
//}
//
//// 获取校验和
//- (Byte)calCheckSum2:(NSData *)data{
//    Byte chksum = 0;
//    Byte *byte = (Byte *)[data bytes];
//    for (NSUInteger i = 0; i < [data length]; i++){
//        chksum += byte[i];
//    }
//    return chksum;
//}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (void)back{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)dealloc
{
    [self.view endEditing:YES];
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [self.view endEditing:YES];
}

@end
